const awaitWrap = (promise) => {
	return promise.then(res => {
		return [res, null]
	}).catch(err => {
		return [null, err]
	})
}
// const baseUrl = "http://192.168.10.22:8082/api/";
//const baseUrl = "http://192.168.2.160:48080/"; //zc
const baseUrl = "http://192.168.2.72:48080/"//pf
//todo token
const serviceReq = (option) => {
	const { url, method, params } = option
	return new Promise((resolve, reject) => {
		uni.request({
			url: baseUrl + url,
			method: method.toUpperCase(),
			data: params,
			header: {
				"Content-Type": "application/json",
				"Authorization": "Bearer 46deb8db1cc64666a23284d2353b1a42"
			},
			success: (res) => {
				if (res.data.code == 0) {
					return resolve(res.data.data)
				} else {
					reject({ code: res.data.code, msg: res.data.msg })
				}
			},
			fail: (err) => {
				reject({ code: 500, msg: "网络错误" })
			}
		})
	})
}

var request = async (option) => {
	return await awaitWrap(serviceReq(option))
}

export { request }